/*
 * 描述： 檢查權限自定義路由斷言工廠類
 * 修改人： Weng.weng
 * 修改时间： 2020年10月21日
 * 项目： gateway-server
 */
package com.tuozixuan.routepredicate;

import java.util.function.Predicate;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.gateway.handler.predicate.AbstractRoutePredicateFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;

/**
 * 檢查權限自定義路由斷言工廠類<br>
 * 
 * @author Weng.weng
 * @version [版本号, 2020年10月21日]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
@Component
public class CheckAuthRoutePredicateFactory extends AbstractRoutePredicateFactory<CheckAuthRoutePredicateFactory.Config> {
    
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    
    public CheckAuthRoutePredicateFactory() {
        super(Config.class);
    }
    
    public CheckAuthRoutePredicateFactory(Class<Config> configClass) {
        super(configClass);
    }

    @Override
    public Predicate<ServerWebExchange> apply(Config config) {
        return exchange -> {
            logger.info("CheckAuthRoutePredicateFactory:{}", config.getName());
            if (config.getName().equals("weng")) {
                return true;
            }
            return false;
        };
    }
    
    public static class Config {
        
        private String name;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
        
    }
}
